package cn.cloud.project.openfeign.controller;

import cn.cloud.project.openfeign.api.Provider2ApiClient;
import cn.cloud.project.openfeign.api.ProviderApiClient;
import feign.Request;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.util.concurrent.TimeUnit;

@RestController
@RequestMapping("/openfeign")
public class OpenFeignController {

    @Resource
    private ProviderApiClient providerApiClient;

    @Resource
    private Provider2ApiClient provider2ApiClient;


    @GetMapping
    public String test(String id) {
        return providerApiClient.test(id);
    }

    @GetMapping("/url")
    public String testUrl(String id) {
        return provider2ApiClient.test(id);
    }


    @GetMapping("/timeout")
    public String testTimeout() {
        return providerApiClient.timeout();
    }

    @GetMapping("/timeout2")
    public String timeout2() {
        return providerApiClient.timeout(new Request.Options(70, TimeUnit.SECONDS, 70, TimeUnit.SECONDS, true));
    }

    /**
     * 测试文件上传
     */
    @PostMapping("/uploadImage")
    public String uploadImage(@RequestParam("file") MultipartFile file) {
        return providerApiClient.uploadImage(file);
    }

}
